package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Publishinfo.PublishInfoDetail_Activity;
import cn.com.infohold.smartcity.api.bean.NewsBean;
import cn.com.infohold.smartcity.parent.ParentActivity;
import library.utils.Utils;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class Publish_Adapter extends RecyclerView.Adapter<Publish_Adapter.mViewHolder> {

    Context context;
    private List<NewsBean> mList;

    public Publish_Adapter(Context context, List<NewsBean> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_publish_info, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {

        NewsBean bean = mList.get(position);
        holder.tv_title.setText(bean.getTitle());
        holder.tv_publishTime.setText(bean.getPublishTime());
        switch (bean.getPolicytype()){
            case 1:
                holder.tv_type.setText("新闻");
                break;
            case 2:
                holder.tv_type.setText("政策");
                break;
            case 3:
                holder.tv_type.setText("法规");
                break;
            default:
                break;

        }

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,PublishInfoDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("publish_detail",bean);
                intent.putExtra("publish_bundle",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder {
        LinearLayout ll_item;
        TextView tv_title;
        TextView tv_type;
        TextView tv_publishTime;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
            tv_type = (TextView) itemView.findViewById(R.id.tv_type);
            tv_publishTime = (TextView) itemView.findViewById(R.id.tv_publishTime);

        }
    }
}
